﻿using ConfExpert.Forms.Base;
using DevTeam;


using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo._7C
{
    public partial class DikilebilecekModel : XForm
    {
        public DikilebilecekModel(DataTable Execs)
        {
            InitializeComponent();
            this.Execs = Execs;
        }

        DataTable Execs;
        private void DikilebilecekModel_Load(object sender, EventArgs e)
        {
            
            btnGetir.ItemClick += btnGetir_ItemClick;
            btnPanoyaAl.ItemClick += btnPanoyaAl_ItemClick;
            Getir();

            gv1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

            splitContainerControl2.AutoSize();

            //splitContainerControl2.AutoSize();
        }

        void btnPanoyaAl_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gv2.EndEditing();
            List<string> ls = new List<string>();
            foreach (DataRow dr in gv2.DataTable().Rows)
                ls.Add(dr["Modello"].ToStr());

            Clipboard.SetText(string.Join(Environment.NewLine, ls.ToArray()));
        }

        void btnGetir_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Getir();
        }

        private void Getir()
        {
            string xE = Execs.Serialize();
            string xM = string.Empty;
            if (gv1.DataSource != null)
                xM = gv1.Serialize();

            gv1.Init("GetModel2Exec", xE, xM);
            gv1.AddDetailGrid(gv2, "Model");
            gv1.AddColumn("Adet", typeof(int), "SUM(Child({FK}).Adet)");

            gv1.FormatAsNumber(0, "Adet");
            gv1.AddSummary("Adet");
            gv2.MakeReadOnly();

            gv1.BestFitColumns();
            gv2.BestFitColumns();
        }
    }
}
